dojo.provide("uws.drawing.ConnectionRestrictionsConstants");

dojo.declare('uws.drawing.ConnectionRestrictionsConstants',null,{
	/*
		A class that dictates whether it is valid or not to connect two components.
	*/
	isAllowable:function(diagramType, connectionType, shape1, shape2){
		
		if(shape2==null){
			if(diagramType == "usecase"){
				if(connectionType == "association"){
					if(shape1=="uws.drawing.usecase.Actor" || shape1=="uws.drawing.usecase.UseCase") return true;
				}else if(connectionType == "dependency"){
					if(shape1=="uws.drawing.usecase.UseCase") return true;
				}else if(connectionType == "generalization"){
					if(shape1=="uws.drawing.usecase.Actor") return true;
				}
			}else if(diagramType == "activity"){
				if(connectionType == "flow"){
					if(shape1=="uws.drawing.activity.Activity" || shape1=="uws.drawing.activity.Decision" || shape1=="uws.drawing.activity.Start") return true;
				}
			}else if(diagramType == "classdiagram"){
				if(connectionType == "generalization"){
					if(shape1=="uws.drawing.classdiagram.ClassBox") return true;
				}
			}else if(diagramType == "sequence"){
				if(connectionType == "flow"){
					if(shape1=="uws.drawing.sequence.ObjectComponent") return true;
				}else if(connectionType == "loop"){
					if(shape1=="uws.drawing.sequence.ObjectComponent") return true;
				}
			}else if(diagramType == "sqlerd"){
				if(connectionType == "relationship"){
					if(shape1=="uws.drawing.sqlerd.Entity") return true;
				}else if(connectionType == "iRelationship"){
					if(shape1=="uws.drawing.sqlerd.Entity" || shape1=="uws.drawing.sqlerd.WeakEntity") return true;
				}else if(connectionType == "connection"){
					if(shape1=="uws.drawing.sqlerd.Entity" || shape1=="uws.drawing.sqlerd.WeakEntity" || shape1=="uws.drawing.sqlerd.Attribute" || shape1=="uws.drawing.sqlerd.KeyAttribute" || shape1=="uws.drawing.sqlerd.DerivedAttribute" || shape1=="uws.drawing.sqlerd.MultivaluedAttribute") return true;
				}
			}
			return false;
		}else{
			if(diagramType == "usecase"){
				if(connectionType == "association"){
					if(shape1=="uws.drawing.usecase.Actor" || shape1=="uws.drawing.usecase.UseCase"){
						if(shape2=="uws.drawing.usecase.Actor" || shape2=="uws.drawing.usecase.UseCase") return true;
					}
				}else if(connectionType == "dependency"){
					if(shape1=="uws.drawing.usecase.UseCase"){
						if(shape2=="uws.drawing.usecase.UseCase") return true;
					}
				}else if(connectionType == "generalization"){
					if(shape1=="uws.drawing.usecase.Actor"){
						if(shape2=="uws.drawing.usecase.Actor") return true;
					}
				}
			}else if(diagramType == "activity"){
				if(connectionType == "flow"){
					if(shape1=="uws.drawing.activity.Activity" || shape1=="uws.drawing.activity.Decision" || shape1=="uws.drawing.activity.Start"){
						if(shape2=="uws.drawing.activity.Activity" || shape2=="uws.drawing.activity.Decision" || shape2=="uws.drawing.activity.Stop") return true;
					}
				}
			}else if(diagramType == "classdiagram"){
				if(connectionType == "generalization"){
					if(shape1=="uws.drawing.classdiagram.ClassBox"){
						if(shape2=="uws.drawing.classdiagram.ClassBox") return true;
					}
				}
			}else if(diagramType == "sequence"){
				if(connectionType == "flow"){
					if(shape1=="uws.drawing.sequence.ObjectComponent"){
						if(shape2=="uws.drawing.sequence.ObjectComponent") return true;
					}
				}else if(connectionType == "loop"){
					if(shape1=="uws.drawing.sequence.ObjectComponent"){
						if(shape2=="uws.drawing.sequence.ObjectComponent") return true;
					}
				}
			}else if(diagramType == "sqlerd"){
				if(connectionType == "relationship"){
					if(shape1=="uws.drawing.sqlerd.Entity"){
						if(shape2=="uws.drawing.sqlerd.Entity") return true;
					}
				}else if(connectionType == "iRelationship"){
					if(shape1=="uws.drawing.sqlerd.Entity" && shape2=="uws.drawing.sqlerd.WeakEntity") return true;
					if(shape2=="uws.drawing.sqlerd.Entity" && shape1=="uws.drawing.sqlerd.WeakEntity") return true;
				}else if(connectionType == "connection"){
					if(shape1=="uws.drawing.sqlerd.Entity" && (shape2=="uws.drawing.sqlerd.Attribute" || shape2=="uws.drawing.sqlerd.KeyAttribute" || shape2=="uws.drawing.sqlerd.DerivedAttribute" || shape2=="uws.drawing.sqlerd.MultivaluedAttribute")) return true;
					if(shape1=="uws.drawing.sqlerd.WeakEntity" && (shape2=="uws.drawing.sqlerd.Attribute" || shape2=="uws.drawing.sqlerd.DerivedAttribute" || shape2=="uws.drawing.sqlerd.MultivaluedAttribute")) return true;
					
					if(shape2=="uws.drawing.sqlerd.Entity" && (shape1=="uws.drawing.sqlerd.Attribute" || shape1=="uws.drawing.sqlerd.KeyAttribute" || shape1=="uws.drawing.sqlerd.DerivedAttribute" || shape1=="uws.drawing.sqlerd.MultivaluedAttribute")) return true;
					if(shape2=="uws.drawing.sqlerd.WeakEntity" && (shape1=="uws.drawing.sqlerd.Attribute" || shape1=="uws.drawing.sqlerd.DerivedAttribute" || shape1=="uws.drawing.sqlerd.MultivaluedAttribute")) return true;
					
					if(
						(shape1=="uws.drawing.sqlerd.KeyAttribute" || shape1=="uws.drawing.sqlerd.MultivaluedAttribute") &&
						(shape2!="uws.drawing.sqlerd.Entity" && shape2!="uws.drawing.sqlerd.WeakEntity")
					){
						return false;
					}
					
					if(
						(shape2=="uws.drawing.sqlerd.KeyAttribute" || shape2=="uws.drawing.sqlerd.MultivaluedAttribute") &&
						(shape1!="uws.drawing.sqlerd.Entity" && shape1!="uws.drawing.sqlerd.WeakEntity")
					){
						return false;
					}
					
					if(
						(shape1=="uws.drawing.sqlerd.Attribute" || shape1=="uws.drawing.sqlerd.KeyAttribute" || shape1=="uws.drawing.sqlerd.DerivedAttribute" || shape1=="uws.drawing.sqlerd.MultivaluedAttribute") && 
						(shape2=="uws.drawing.sqlerd.Attribute" || shape2=="uws.drawing.sqlerd.KeyAttribute" || shape2=="uws.drawing.sqlerd.DerivedAttribute" || shape2=="uws.drawing.sqlerd.MultivaluedAttribute")
					){
						return true;
					}
				}
			}
			return false;
		}
	},
	allowLoop:function(diagramType, connectionType){
		if(diagramType == "sequence"){
			if(connectionType == "loop"){
				return true;
			}
		}else if(diagramType == "sqlerd"){
			if(connectionType == "relationship"){
				return true;
			}
		}
		
		return false;
	}
});